package com.woniu.humanresource.service.impl;

import com.woniu.humanresource.dao.TrainingDao;
import com.woniu.humanresource.entity.PageBean;
import com.woniu.humanresource.entity.Training;
import com.woniu.humanresource.service.TrainingService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

@Service
public class TrainingServiceImpl implements TrainingService {

    @Resource
    TrainingDao trainingDao;

    @Override
    public PageBean<Training> getAllTrainingByCondition(Training training, int pageIndex, int pageSize) {

        List<Training> trainings = trainingDao.selectTrainingCondition(training, pageIndex, pageSize);
        PageBean<Training> pageBean = new PageBean<>();
        pageBean.setBeanList(trainings);
        pageBean.setPageIndex(pageIndex);
        pageBean.setPageSize(pageSize);
        pageBean.setTotalRecord(trainingDao.selectTotalRecordCondition(training));
        return pageBean;
    }

    @Override
    public void deleteTraining(int tid) {
        trainingDao.deleteTraining(tid);
    }

    @Override
    public void addTraining(Training training) {
        trainingDao.insertTraining(training);
    }

    @Override
    public void updateTraining(Training training) {
        trainingDao.updateTraining(training);
    }
}
